package com.h.ops.controller;

import com.h.ops.constant.Constants;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/consumer")
@RestController
public class ConsumerController {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @RequestMapping("/get")
    // 从中间件的获取消息的方法，这个是 拉模式 每次只能获取一个消息
    public String get() {
        Message message = rabbitTemplate.receive(Constants.CLUSTER_QUEUE);
        System.out.println("获取的信息为: " + message);
        return "获取中间件消息的拉模式获取成功";
    }
}
